<?php

/**
 * SoftwaresController - Softwares
 *
 * @author Fernando Dias Oliveira <rodox17@gmail.com>
 * @package intranet
 * @subpackage controller
 */

class SoftwaresController extends AppBaseController
{
	public function init()
	{
		parent::init();
		
		$this->view->title = "Softwares";		
		
		if($this->_request->isPost())
		{
			extract($_POST, EXTR_OVERWRITE);
			
			$documento = new INT005();
			
			$documento->setINT005_cod($cod);
			$documento->setINT005_nome($INT005_nome);
			$documento->setINT005_descricao($INT005_descricao);
			
			if($INT005_url)
			{
				$documento->setINT005_url($INT005_url);
			}
			else
			{
				Upload::$type = false;
				
				$documento->setINT005_url(Upload::save());
			}
			
			$documento->save();
			
			$this->_redirect($this->controller . "/");
		}
	}

    public function indexAction() 
    {
		$this->grid("INT005");
    }
    
    public function adicionarAction()
    {
    	
    }
    
    public function excluirAction()
    {
    	$documento = new INT005();
    	
    	$id = $this->getArrCod($this->_request->getParam("cod"));
    	
    	$documento->excluir($id);
    	
    	$this->_redirect("$this->controller/");
    }
    
    public function editarAction()
    {
    	$software = new INT005();
    	
    	$cod = $this->_request->getParam("cod");
    	
    	$arr = $software->getDownloadById($cod);
    	
    	$this->view->doc = $arr[0];
    }
    
    public function downloadAction()
    {
    	$documento = new INT005();
    	
    	$id = $this->getArrCod($this->_request->getParam("cod"));
    	
    	$doc = $documento->getDownloadById(key($id));
    	
    	Download::get($doc[0]["INT005_url"]);
    }
}
